const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('m_consumers', {
    id: {
      autoIncrement: true,
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true,
      comment: '消费者id'
    },
    uid: {
      type: DataTypes.BLOB,
      allowNull: true,
      defaultValue: Sequelize.Sequelize.literal('uuid_to_bin(uuid(),1)'),
      comment: 'uid'
    },
    nickname: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '消费者昵称'
    },
    fullname: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '姓名'
    },
    password: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '密码'
    },
    salt: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '加密盐'
    },
    gender: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '性别 male-男 female-女 secrecy-保密'
    },
    headimg: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: '头像url'
    },
    tel: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '电话'
    },
    email: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '邮箱'
    },
    company: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '公司名称'
    },
    address: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '收货地址，数组形式，可多个'
    },
    state: {
      type: DataTypes.SMALLINT,
      allowNull: true,
      defaultValue: 1,
      comment: '状态 0-停用 1-启用'
    },
    create_ip: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '注册ip'
    },
    last_login_time: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '最后登录时间'
    },
    last_login_ip: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '最后登录的ip'
    },
    login_count: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '登录次数'
    },
    create_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '注册时间'
    }
  }, {
    sequelize,
    tableName: 'm_consumers',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' }
        ]
      },
      {
        name: 'idx_uid',
        using: 'BTREE',
        fields: [
          { name: 'uid' }
        ]
      }
    ]
  });
};
